package com.example.function.project.dao.one;

import com.example.common.dao.BaseJpaRepository;
import com.example.function.project.model.one.ProjectAssetsGroup;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ProjectAssetsGroupJpaRepository extends BaseJpaRepository<ProjectAssetsGroup, Long>{

    @Query(value = "select t.project_id_fk as projectId from tbl_project_assets_group t ,tbl_rp_assets_type a,tbl_rp_assets c \n" +
            "WHERE t.assets_id_fk = c.rp_assets_id and c.rp_assets_type_id_fk = a.rp_assets_type_id and a.rp_assets_type_id = :typeId",nativeQuery = true)
    public List<Long> findProjectIdsByAssetsTypeId(@Param("typeId") Long typeId);



    @Query(value = "select DISTINCT(s.rp_assets_type_name) as typeName from tbl_project_assets_group t , tbl_rp_assets a ,tbl_rp_assets_type s\n" +
            "WHERE t.assets_id_fk = a.rp_assets_id and a.rp_assets_type_id_fk = s.rp_assets_type_id\n" +
            "and t.project_id_fk = :projectId" ,nativeQuery = true)
    public List<String> findAssetsTypeNamesByPorjectId(@Param("projectId") Long projectId);
}
